package servlets;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintStream;

/**
 * Created by hadoop on 17-6-13.
 * 处理form.jsp的请求
 */
@WebServlet(name = "FirstServlet", urlPatterns = {"/servlet001"})
public class FirstServlet extends HttpServlet{
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String gender = req.getParameter("gender");
        String[] colors = req.getParameterValues("color");
        String country = req.getParameter("country");

        PrintStream out = new PrintStream(resp.getOutputStream());
        out.println("<html><head><title>FirstServlet</title></head><body>");
        out.println("Name: "+name+"<br>");
        out.println("Gender: "+gender+"<br>");
        out.println("Colors: ");
        for(String c : colors){
            out.println(c+" ");
        }
        out.println("<br>");
        out.println("Country: "+country+"<br>");
        out.println("</body></html>");
    }
}
